package com.huaruan.youdi.receiver;

import android.content.Context;
import android.os.Bundle;
import android.util.Log;

import com.google.gson.Gson;
import com.huaruan.youdi.eventbus.EventBus;
import com.huaruan.youdi.eventbus.EventNames;
import com.huaruan.youdi.utils.AppUtils;

import cn.jpush.android.api.CustomMessage;
import cn.jpush.android.service.JPushMessageReceiver;

/**
 * 自定义JPush接收器
 * <p>
 * 如果不定义这个 Receiver，则：
 * 1) 默认用户会打开主界面
 * 2) 接收不到自定义消息
 */
public class JPushReceiver extends JPushMessageReceiver {

    @Override
    public void onMessage(Context context, CustomMessage customMessage) {
        super.onMessage(context, customMessage);
        String content = customMessage.extra;
        Log.e("极光极光极光极光极光极光", content);
        Gson mGson = new Gson();
        EventBus.getInstance().notifiDataUpdate(EventNames.REFRESH_MAIN, "");
//        JPushModel model = mGson.fromJson(content, JPushModel.class);
//        if ("1".equals(model.type)) {
//            Bundle bundle = new Bundle();
//            bundle.putString("toAccount", model.fromAccount);
//            bundle.putString("toUserName", model.fromUserName);
//            bundle.putString("toUserImageUrl", model.fromUserImageUrl);
//            AppUtils.jump(context, ChatActivity.class, bundle);
//        }
    }

}